class EventBus {
	constructor () {
		this.events = this.events || new Object()
	}

	emit (type, ...args) {
		let e
		e = this.events[type]
		try {
			if (Array.isArray(e)) {
				for (let i = 0; i < e.length; i++) {
					e[i].apply(this, args)
				}
			} else {
				e[0].apply(this, args)
			}
		} catch (e) {
			console.warn(`未找到${type}的监听`)
		}
	}
	addListener (type, fun) {
		const e = this.events[type]

		if (!e) {
			this.events[type] = [fun]
		} else {
			e.push(fun)
		}
	}
}
export const eventBus = new EventBus();
